package thinkingInJava.generics.SelfBound;
// page 408 自限定
//: generics/SelfBoundingAndCovariantArguments.java

interface SelfBoundSetter<T extends SelfBoundSetter<T>> {
void set(T arg);
}

interface Setter extends SelfBoundSetter<Setter> {}

public class SelfBoundingAndCovariantArguments {
void testA(Setter s1, Setter s2, SelfBoundSetter sbs) {
  s1.set(s2);
  // 自限定可使 set 只接受一种类型(Setter).而如果是普通类继承重载,
  // 则函数可接受基类及所有继承类.自限定则相当于覆盖,而不是重载.
  // 可以对比 PlainGenericInheritance.java
  // s1.set(sbs); // Error: 
  // set(Setter) in SelfBoundSetter<Setter>
  // cannot be applied to (SelfBoundSetter)
}
} ///:~

